package com.weixinli.web.actions;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.weixinli.beans.Admin;
import com.weixinli.biz.IAdminBiz;
import com.weixinli.utils.SessionAttributeName;
import com.weixinli.web.actions.model.JsonObject;
@Controller("AdminAction")
public class AdminAction extends ActionSupport implements ModelDriven<Admin> ,SessionAware {
	private static final long serialVersionUID = -4373077772187983126L;
	private IAdminBiz iAdminBiz;
	private Admin admin;
	private JsonObject jsonObject;
	private Map<String, Object> session;
	private SessionAttributeName sessionAttributeName;
	/**
	 * 管理员登录
	 * @return
	 */
	public String LoginAdmin(){
		Admin adm=iAdminBiz.checkAdmin(admin);
		if(adm==null){
			jsonObject.setResult(0);
		}else{
			jsonObject.setObj(adm);
			jsonObject.setResult(1);
			session.put(sessionAttributeName.ADMINLOGIN,adm);
		}
		return "success";
	}
	
	@Resource(name="iAdminBiz")
	public void setiAdminBiz(IAdminBiz iAdminBiz) {
		this.iAdminBiz = iAdminBiz;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public Admin getModel() {
		admin=new Admin();
		return admin;
	}

	public JsonObject getJsonObject() {
		return jsonObject;
	}
	@Resource(name="jsonObject")
	public void setJsonObject(JsonObject jsonObject) {
		this.jsonObject = jsonObject;
	}
	public void setSession(Map<String, Object> session) {
		this.session=session;
	}
	@Resource(name="sessionAttributeName")
	public void setSessionAttributeName(SessionAttributeName sessionAttributeName) {
		this.sessionAttributeName = sessionAttributeName;
	}	
}
